package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.basic.dto.consignee.ConsigneeRewriteDTO;
import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.open.domain.source.utils.MappingOrder;
import com.wlyuan.open.dto.OpenConsigneeSyncDTO;
import lombok.var;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author yuanzheng
 */
public class ConsigneeAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingIds.class,
            MappingOrder.class
    }, imports = {
            NamedStatus.class,
    })
    public interface Assembler {
        @Mappings({
                @Mapping(source = "consigneeConfig", target = "consigneeConfigSet"),
                @Mapping(source = "tenantId", target = "consigneeConfigSet.tenantId"),
                @Mapping(constant = "0L", target = "consigneeConfigSet.userId"),
        })
        ConsigneeRewriteDTO assemble(OpenConsigneeSyncDTO source);

    }

    public static ConsigneeRewriteDTO assemble(OpenConsigneeSyncDTO source, Long customerId) {
        var creation = ASSEMBLER.assemble(source);
        creation.setCustomerId(customerId);
        return creation;
    }

}
